package b1.controls.basic
{
	import flash.display.Sprite;

	public class ProgressBar extends Sprite
	{
		//0 - 1
		public var percentage:Number;
		
		private var progressBarSprite:Sprite;
		//progress bar length when complete (100) 
		private var completeLength:Number;
		
		public function ProgressBar(CProgressBarFrame:Class, CProgressBar:Class, percentage:Number = 0, gap:int = 5)
		{
			super();
			this.percentage = percentage;
			//Add frame
			var progressBarFrameSprite:Sprite = new CProgressBarFrame();
			addChild(progressBarFrameSprite);
			//Add progressbar
			progressBarSprite = new CProgressBar();
			addChild(progressBarSprite);
			progressBarSprite.x = gap;
			progressBarSprite.y = progressBarFrameSprite.y + gap;
			progressBarSprite.width = 0;
			progressBarSprite.height = progressBarFrameSprite.height - 2 * gap;
			completeLength = progressBarFrameSprite.width - 2 * gap;
			updateProgress(percentage);
		}
		
		public function updateProgress(percentage:Number):void
		{
			if (percentage < 0)
				this.percentage = 0;
			else if (percentage > 1)
				this.percentage = 1;
			else 
				this.percentage = percentage;
			progressBarSprite.width = this.percentage * completeLength;
		}
	}
}